package com.chixing.ih.config;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-27
 * Time: 20:01
 *
 * @version 1.0
 */


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger 配置类
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApiYan1(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoYan1())
                .enable(flag)
                .groupName("系统模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.chixing.ih.module.system.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiYan2(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoYan2())
                .enable(flag)
                .groupName("程序员模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.chixing.ih.module.programmer.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiWang(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoWang())
                .enable(flag)
                .groupName("任务模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.chixing.ih.module.task.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createRestApiFei(Environment environment) {
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoFei())
                .enable(flag)
                .groupName("管理员模块")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.chixing.ih.module.admin.controller"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfoYan1() {
        return new ApiInfoBuilder()
                .title("IT帮网站->后台说明文档")
                .description("刘岩->系统模块")
                .termsOfServiceUrl("https://www.proginn.com/")
                .contact("刘岩")
                .version("1.0")
                .build();
    }

    private ApiInfo apiInfoYan2() {
        return new ApiInfoBuilder()
                .title("IT帮网站->后台说明文档")
                .description("刘岩->管理员模块")
                .termsOfServiceUrl("https://www.proginn.com/")
                .contact("刘岩")
                .version("1.0")
                .build();
    }

    private ApiInfo apiInfoWang() {
        return new ApiInfoBuilder()
                .title("IT帮网站->后台说明文档")
                .description("张从旺->任务模块")
                .termsOfServiceUrl("https://www.proginn.com/")
                .contact("张从旺")
                .version("1.0")
                .build();
    }


    private ApiInfo apiInfoFei() {
        return new ApiInfoBuilder()
                .title("IT帮网站->后台说明文档")
                .description("韩飞->任务模块")
                .termsOfServiceUrl("https://www.proginn.com/")
                .contact("韩飞")
                .version("1.0")
                .build();
    }

}
